<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>AdminLTE 2 | Registration Page</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="../public/bower_components/bootstrap/dist/css/bootstrap.min.css"     th:href="@{/bower_components/bootstrap/dist/css/bootstrap.min.css}">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../public/bower_components/font-awesome/css/font-awesome.min.css"    th:href="@{/bower_components/font-awesome/css/font-awesome.min.css}">
  <!-- Ionicons -->
  <link rel="stylesheet" href="../public/bower_components/Ionicons/css/ionicons.min.css"             th:href="@{/bower_components/Ionicons/css/ionicons.min.css}">
  <!-- Theme style -->
  <link rel="stylesheet" href="../public/dist/css/AdminLTE.min.css"                                     th:href="@{/dist/css/AdminLTE.min.css}">
  <!-- iCheck -->
  <link rel="stylesheet" href="../public/plugins/iCheck/square/blue.css"                                th:href="@{/plugins/iCheck/square/blue.css}">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <!--<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>-->
  <!--<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>-->
  <![endif]-->

  <!-- Google Font -->
  <!--<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">-->
  <style type="text/css">
    .glyphicon-eye-close,.glyphicon-eye-open{
      pointer-events: auto;
      cursor: pointer;
    }
  </style>
</head>
<body class="hold-transition register-page">
<div class="register-box">
  <div class="register-logo">
    <a href="/index2.html"><b>Admin</b>LTE</a>
  </div>
  <div class="register-box-body">
    <p class="login-box-msg">Register a new membership</p>

    <form action="/register" method="post">
      <div class="form-group has-feedback">
        <input id="username" name="username" type="text" class="form-control" placeholder="用户名">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input id="password" name="password" type="password" class="form-control" placeholder="输入密码">
        <span class="glyphicon glyphicon-eye-close form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input id="password2" name="password2" type="password" class="form-control" placeholder="重复输入密码">
        <span class="glyphicon glyphicon-eye-close form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input id="agree" name="agree" type="checkbox"> 已阅读并同意<a href="#">协议</a>
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat">注&nbsp;&nbsp;&nbsp;&nbsp;册</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
    <br>
    <br>
    <br>
    <div class="container-fluid">
      <div class="row">
        <div class="col-xs-12 text-center">
          <a th:href="@{/login}">已有秘籍?返回登录</a>
        </div>
      </div>
    </div>
  </div>
  <!-- /.form-box -->
</div>
<!-- /.register-box -->

<!-- jQuery 3 -->
<script src="../public/bower_components/jquery/dist/jquery.min.js"              th:src="@{/bower_components/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../public/bower_components/bootstrap/dist/js/bootstrap.min.js"    th:src="@{/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
<!-- iCheck -->
<script src="../public/plugins/iCheck/icheck.min.js"                    th:src="@{/plugins/iCheck/icheck.min.js}"></script>
<!--jQuery.Validate及语言包-->
<script src="../static/libs/jquery/validate/jquery.validate.min.js"   th:src="@{/libs/jquery/validate/jquery.validate.min.js}"></script>
<script src="../static/libs/jquery/validate/messages_zh.min.js"        th:src="@{/libs/jquery/validate/messages_zh.min.js}"    ></script>
<!--弹出层-->
<script src="../static/libs/layer/layer.min.js"                          th:src="@{/libs/layer/layer.min.js}"></script>
<!--自定义通用库-->
<script src="../static/js/common.js"                                         th:src="@{/js/common.js}"></script>
<script>
  "use strict";

  $(function () {
    $('input').iCheck({
      checkboxClass:  'icheckbox_square-blue',
      radioClass:     'iradio_square-blue',
      increaseArea:   '20%' /* optional */
    });

      //设置Form验证与提交
      var ctx = "/"
      $("form").validate({
          //验证规则
          rules:{
              username:{
                  required:true,          //必须存在用户名
                  rangelength: [4, 16],   //用户名长度限制
                  remote: {                //服务器验证用户名是否唯一
                      url: ctx + "checkUsernameUnique",   //远程验证Url
                      type: "post",                          //POST
                      dataType: "json",                     //预期服务器返回的类型
                      data: {                                 //请求数据
                          username : function() {
                              return $.trim($("#username").val());
                          }
                      }
                  }
              },
              password:{
                  required:true,
                  rangelength: [6, 32],
              },
              password2:{
                  equalTo: "#password"
              }
          },
          //自定义错误消息
          messages: {
              "username": {
                  remote: "用户已经存在"
              }
          },
          //验证失败时高亮显示
          highlight: function(input, errorClass, validClass){
              $(input).parent().addClass("has-error");
          },
          //验证成功时消除高亮显示
          unhighlight: function(input, errorClass, validClass){
              $(input).parent().removeClass("has-error");
          },
          //Field错误信息放置地点
          errorPlacement: function(errorLabel, input){
              errorLabel.insertAfter($(input).parent())
          },
          //验证成功时提交
          submitHandler:function(form){
              let $form = $(form);
              $.post($form.attr('action'), $form.serialize(), function () {
                  $.modal.msgSuccess("注册成功,2秒后跳转到登陆页面...");
                  setTimeout(function () {
                      window.location.href = ctx + "login";
                  }, 2000);
              });
          }
      })
  });
</script>
</body>
</html>
